package com.atguigu.exer;

/**
 * @author yihu
 * @email 1057202547@qq.com
 * @create 2020-11-2020-11-19-23:41
 * @des
 *
 * 创建两个分线程，其中一个线程遍历100以内的偶数，另一个线程去遍历100以内的奇数
 *
 */
public class ThreadDemo {
    public static void main(String[] args) {
        Mythread t1 = new Mythread(1);
        t1.start();

        Mythread t2 = new Mythread(2);
        t2.start();
    }
}

class  Mythread extends  Thread {

    private final int type;
    Mythread(int type){
       super();
       this.type = type;
    }

    @Override
    public void run() {
        if(this.type%2 == 0){
            printEven();
            return;
        }
        printOdd();
    }

    /**
     * 打印100以内的偶数
     */
    public  void printEven(){
        for (int i = 0; i < 100; i++) {
            if(i%2 == 0){
                System.out.println(Thread.currentThread().getName() + ":"+  i);
            }
        }
    }

    /**
     * 打印100以内的奇数
     */
    public  void printOdd(){
        for (int i = 0; i < 100; i++) {
            if(i%2 != 0){
                System.out.println(Thread.currentThread().getName() + ":"+  i);
            }
        }
    }

}
